#ifndef __IO_MODULE_H__
#define __IO_MODULE_H__

#include "common.h"
#include "global_config.h"

/* IO channel definitions */
#define DIGITAL_INPUT_CHANNELS  12
#define DIGITAL_OUTPUT_CHANNELS 12

/* Input debounce states */
typedef enum {
    DEBOUNCE_IDLE = 0,
    DEBOUNCE_RISING,
    DEBOUNCE_FALLING,
    DEBOUNCE_STABLE
} debounce_state_t;

/* IO control commands */
typedef enum {
    IO_CMD_SET_OUTPUT = 1,
    IO_CMD_GET_INPUT,
    IO_CMD_GET_OUTPUT,
    IO_CMD_SAFE_STATE
} io_cmd_t;

/* IO message data structures */
typedef struct {
    uint8_t channel;
    rt_bool_t state;
} io_set_output_t;

typedef struct {
    uint8_t channel;
    rt_bool_t state;
} io_get_state_t;

/* Function declarations */
rt_err_t io_module_init(void);
void io_thread_entry(void *parameter);
rt_bool_t io_get_input_state(uint8_t channel);
rt_bool_t io_get_input_valid_state(uint8_t channel);
rt_err_t io_set_output_state(uint8_t channel, rt_bool_t state);
rt_bool_t io_get_output_state(uint8_t channel);
rt_err_t io_set_safe_state(void);

/* External configuration access */
extern io_config_t *io_get_config(void);

#endif /* __IO_MODULE_H__ */